<template>
    <div>
        <el-container  class="page">
            <el-header>
                <span>才华的博客后台管理</span>
                <div class="exit">
                    <span class="user_info" v-if="username !== ''">{{ username }}</span>
                    <el-button class="user_info" type="danger" round @click='jumpLogin' size="small" v-else>
                        登录
                    </el-button>
                    <el-button type="text" round @click='exitClick' size="mini">
                        退出
                    </el-button>
                </div>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <Nav></Nav>
                </el-aside>
                <el-main>
                    <router-view :key="$route.fullPath"></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import Nav from '@/components/Nav.vue';
export default {
    components: { Nav },
    data() {
        return {
            username: ""
        }
    },
    methods: {
        jumpLogin() {
            this.$router.push("/login")
        },
        getUsername() {
            this.username = window.sessionStorage.getItem("Username")
            if (this.username === null) {
                this.username = ""
            }
        },
        exitClick() {
            window.sessionStorage.clear()
            this.$router.push("/login")
        }
    },
    mounted() {
        this.getUsername()
    }
}
</script>

<style scoped>
.page {
    width: 100%;
    height: 100%;
}
.el-header,.el-aside{
    background-color: rgba(3, 12, 54,1);
}
.el-aside{
    height: 567.24px;
}
.el-header{
    text-align: center;
    line-height: 50px;
    color: #fff;
}
.exit{
    margin-top: 10px;
    float: right;
}
.user_info {
    margin-right: 2px;
}
</style>>
